#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <stdlib.h>

int main()
{
  pid_t id = fork();
  
  if(id == 0){
    printf("I am a process!\n");
    sleep(3); 
    //execl("/usr/bin/ls", "ls", "-a", "-l", "-i", NULL);
    char *envp[]={"MYPATH=youcanseeme!", NULL};
    execle("./mycmd", "mycmd", NULL, envp);
    printf("replace fail\n");
    exit(1);
  }

  int status = 0;
  pid_t ret = waitpid(id, &status, 0);
  if(ret > 0){
    printf("wait succesfully\n");
    printf("child exit code:%d\n", WEXITSTATUS(status));
  }
  else{
    printf("wait fail;\n");
  }
  return 0;
}
